import pandas as pd
import yaml

from yaml import SafeLoader

from datareport.api import ImageUtil
from datareport.api.DataSource import DataSource
from datareport.impl import StaticDF
from datareport.impl.paragraph.base.BaseParagraph import BaseParagraph
from datareport.api.annotation.Style import style


@style(space_before=1.5,first_line_indent=0)
class KaiZhanQingKuang_zhuti_zhengti_keyan_45(BaseParagraph):
    """
    组织生活开展主题分析-整体情况-科研
    """

    def __init__(self):
        super().__init__()
        self.text = ''''''
        self.sort = 35
        self.section = 12

    def plot(self, df, plt):
        pass

    def getData(self, result):
        pass

    def start(self, conn, year, plt):
        df = StaticDF.getDF()
        values=[]
        orgs=df['partyOrgName'].drop_duplicates().tolist()
        for o in orgs:
            values.append(len(df[(df['partyOrgName']==o) & (df['topicLabel'].str.contains('2002'))]))
        self.image=ImageUtil.plot(pd.DataFrame(columns=['党组织','科研专题'],data = {'党组织': orgs, '科研专题': values}),ylable='二级党组织科研专题数')


def list2str(l):
    return '、'.join(l)


if __name__ == '__main__':
    with open('D:\work\sanhuiyike\datareport\config.yaml', encoding='utf-8') as f:
        data = yaml.load(f, Loader=SafeLoader)
    con = DataSource(data['datasource']).conn
    KaiZhanQingKuang_zhuti_zhengti_keyan().start(con, 2023, '')
